package edu.uwm.capstone.diasmart.database;

import edu.uwm.capstone.util.DebugUtil;
import edu.uwm.capstone.util.Identifiable;
import edu.uwm.capstone.util.StringUtil;

public class Reminder implements Identifiable {
	public static final int[] ALL_PERIODS = new int[3];
	public static final int DAYS_PERIOD_TYPE = 2;
	public static final int HOURS_PERIOD_TYPE = 1;
	public static final int MINUTES_PERIOD_TYPE = 1;
	private String categories;
	private long[] categoryIDs = null;
	private long id = -1L;
	private boolean modified = false;
	private String name;
	private int periodTime;
	private int periodType;
	private boolean persistent;
	private String text;
	private int[] typeIDs = null;
	private String types;
	private int userOrder = 0;
	static {
		ALL_PERIODS[0] = 1;
		ALL_PERIODS[1] = 2;
	}

	public Reminder() {
	}

	public Reminder(long id, String name) {
		this.id = id;
		this.name = name;
	}

	public Reminder(long id, String name, String text, int periodTime,
			int periodType, int userOrder, String categories, String types,
			boolean persistent) {
		this.id = id;
		this.name = name;
		this.text = text;
		this.periodTime = periodTime;
		this.periodType = periodType;
		this.userOrder = userOrder;
		this.categories = categories;
		this.types = types;
		this.persistent = persistent;
	}

	public String getCategories() {
		return this.categories;
	}

	public long[] getCategoryIDs() {
		if (this.categoryIDs != null)
			return this.categoryIDs;
		if (StringUtil.isEmpty(this.categories))
			return new long[0];
		String[] arrayOfString = this.categories.split(",");
		this.categoryIDs = new long[arrayOfString.length];
		int i = 0;
		while (true) {
			if (i >= arrayOfString.length)
				return this.categoryIDs;
			try {
				this.categoryIDs[i] = Long.parseLong(arrayOfString[i]);
				i++;
			} catch (NumberFormatException localNumberFormatException) {
				while (true) {
					DebugUtil.debug(this, "Invalid category ID in reminder: '"
							+ arrayOfString[i] + "'");
					this.categoryIDs[i] = -5L;
				}
			}
		}
	}

	public long getInterval() {
		switch (this.periodType) {
		default:
			throw new RuntimeException("Invalid period type set for reminder");
		case 0:
			return 1000 * (60 * this.periodTime);
		case 1:
			return 1000 * (60 * (60 * this.periodTime));
		case 2:
		}
		return 1000 * (60 * (60 * (24 * this.periodTime)));
	}

	public String getName() {
		return this.name;
	}

	public int getPeriodTime() {
		return this.periodTime;
	}

	public int getPeriodType() {
		return this.periodType;
	}

	public boolean getPersistent() {
		return this.persistent;
	}

	public String getText() {
		return this.text;
	}

	public int[] getTypeIDs() {
		if (this.typeIDs != null)
			return this.typeIDs;
		if (StringUtil.isEmpty(this.types))
			return new int[0];
		String[] arrayOfString = this.types.split(",");
		this.typeIDs = new int[arrayOfString.length];
		for (int i = 0;; i++) {
			if (i >= arrayOfString.length)
				return this.typeIDs;
			this.typeIDs[i] = Integer.parseInt(arrayOfString[i]);
		}
	}

	public String getTypes() {
		return this.types;
	}

	public int getUserOrder() {
		return this.userOrder;
	}

	public boolean isDefaultCategory(long paramLong) {
		long[] arrayOfLong = getCategoryIDs();
		for (int i = 0; i < arrayOfLong.length; i++) {
			if (arrayOfLong[i] == paramLong)
				return true;
		}
		return false;
	}

	public boolean isDefaultType(int paramInt) {
		int[] arrayOfInt = getTypeIDs();
		for (int i = 0;; i++) {
			if (i >= arrayOfInt.length)
				return false;
			if (arrayOfInt[i] == paramInt)
				return true;
		}
	}

	public boolean isModified() {
		return this.modified;
	}

	public void setCategories(String paramString) {
		if (!StringUtil.isEqual(this.categories, paramString)) {
			this.categories = paramString;
			this.modified = true;
			this.categoryIDs = null;
		}
	}

	public void setId(long paramLong) {
		this.id = paramLong;
	}

	public void setModified(boolean paramBoolean) {
		this.modified = paramBoolean;
	}

	public void setName(String paramString) {
		if (!StringUtil.isEqual(paramString, this.name)) {
			this.name = paramString;
			this.modified = true;
		}
	}

	public void setPeriodTime(int paramInt) {
		if (this.periodTime != paramInt) {
			this.periodTime = paramInt;
			this.modified = true;
		}
	}

	public void setPeriodType(int paramInt) {
		if (this.periodType != paramInt) {
			this.periodType = paramInt;
			this.modified = true;
		}
	}

	public void setPersistent(boolean paramBoolean) {
		if (paramBoolean != this.persistent) {
			this.persistent = paramBoolean;
			this.modified = true;
		}
	}

	public void setText(String paramString) {
		if (!StringUtil.isEqual(paramString, this.text)) {
			this.text = paramString;
			this.modified = true;
		}
	}

	public void setTypes(String paramString) {
		if (!StringUtil.isEqual(this.types, paramString)) {
			this.types = paramString;
			this.modified = true;
			this.typeIDs = null;
		}
	}

	public void setUserOrder(int paramInt) {
		if (paramInt != this.userOrder) {
			this.userOrder = paramInt;
			this.modified = true;
		}
	}

	public String toString() {
		return this.name;
	}

	@Override
	public long getId() {

		return this.id;
	}

}
